package pl.inea;

import android.app.Activity;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.VideoView;

public class PlayScreen extends Activity {
	private VideoView mVideoView;
	private RelativeLayout rel1, rel2;
	private String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
	private boolean clicked1, clicked2;
	private ImageView imageView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.play_screen);

		rel1 = (RelativeLayout) findViewById(R.id.rel1);
		rel2 = (RelativeLayout) findViewById(R.id.rel2);
		mVideoView = (VideoView) findViewById(R.id.surface_view);
		imageView = (ImageView) findViewById(R.id.info_view);
		clicked1 = false;
		clicked2 = false;
		rel1.setBackgroundColor(Color.LTGRAY);
		rel2.setBackgroundColor(Color.LTGRAY);

		rel1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LayoutParams layoutParams = rel1.getLayoutParams();
				if (clicked1) {
					layoutParams.width = 75;
					rel1.setLayoutParams(layoutParams);
					// mVideoView.pause();
				} else {
					layoutParams.width = 25;
					rel1.setLayoutParams(layoutParams);
					// mVideoView.start();
				}
				if (clicked1 && clicked2) {
					mVideoView.pause();
					imageView.setVisibility(View.GONE);
				} else {
					mVideoView.start();
					imageView.setVisibility(View.VISIBLE);

				}
				clicked1 = !clicked1;
			}
		});

		rel2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LayoutParams layoutParams = rel2.getLayoutParams();
				if (clicked2) {
					layoutParams.width = 75;
					rel2.setLayoutParams(layoutParams);
					// mVideoView.pause();
				} else {
					layoutParams.width = 25;
					rel2.setLayoutParams(layoutParams);
					// mVideoView.start();
				}
				if (!clicked1 && !clicked2) {
					mVideoView.pause();
					imageView.setVisibility(View.INVISIBLE);
				} else {
					mVideoView.start();
					imageView.setVisibility(View.VISIBLE);
				}
				clicked2 = !clicked2;
			}
		});

		mVideoView.setVideoURI(Uri.parse(SrcPath));
		mVideoView.setMediaController(new MediaController(this));
		mVideoView.requestFocus();
	}
}
